<cfsilent><!---

CF_Kalendar

COPYRIGHT & LICENSING INFO
-------------------------------------------------------------------

Copyright 2008 TJ Downes - tdownes@sanative.net - http://www.sanative.net

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

--->

<!--- attributes.calendarLinkPage - the page that the user is taken to when they click an event --->
<cfparam name="Attributes.calendarLinkPage" type="string" default="" />
<!--- attributes.ExcludeTimeHeader - boolean to specifiy if the header on the calendar for times is displayed --->
<cfparam name="Attributes.ExcludeTimeHeader" type="boolean" default="no" />
<!--- attributes.KalendarRequest  contains the request based data and rules for Kalendar. --->
<cfparam name="Attributes.KalendarRequest" type="any" />
<!--- attributes.urlAddString - a URL string to add to the calendarLinkPage attribute --->
<cfparam name="Attributes.urlAddString" type="string" default="" />
<!--- attributes.view - defines which display mode to show: day, week, weeklist, month, condensed --->
<cfparam name="Attributes.view" type="string" default="list" />
<!--- attributes.ToolTipFormatter - utility object that contains methods to format tooltips --->
<cfparam name="Attributes.ToolTipFormatter" type="any" />

<!--- Config --->
<!--- TODO: something to make this easier, or be shared across all display views so we dont have the same code in multiple view files --->
<cfscript>
	EventRecords = attributes.KalendarRequest.getReturnedEvents(session.user,request.timezones);
	KalendarConfig = attributes.KalendarRequest.getKalendarConfig();
	optionBarVars.view = attributes.view;
	optionBarVars.KalendarRequest = attributes.KalendarRequest;
</cfscript>

</cfsilent>

<cfmodule template="OptionBar.cfm" attributecollection="#optionBarVars#">

<!--- WEEK CALENDAR --->
<cfoutput>
<table class="calendarTable">
<tr>
	<cfloop from="1" to="7" index="i">
	<td class="eventDayName"><cfoutput>#left(dayOfWeekAsString(i), 3)#</cfoutput></td>
	</cfloop>
</tr>
<tr>
	<cfloop index="LoopIndex" from="0" to="6">
	<cfset thisDay = DateAdd('d', LoopIndex, attributes.KalendarRequest.getFirstDateOfWeek()) />
	<td class="eventDayHeader"><cfif Month(CreateODBCDate(thisDay)) eq Month(attributes.KalendarRequest.getLinkDate())><cfoutput>#Day(thisDay)#</cfoutput><cfelse>&nbsp;</cfif></td>
	</cfloop>
</tr>
</tr>
</cfoutput>
<!--- Output week --->
<tr>
<cfloop index="LoopIndex" from="0" to="6">
	<cfset thisDay = DateAdd('d', LoopIndex, attributes.KalendarRequest.getFirstDateOfWeek()) />
	<td class="eventDay">
	<cfloop index="i" from="1" to="#ArrayLen(EventRecords)#">
	<cfoutput>
	<cfif DateDiff("d",CreateODBCDate(eventRecords[i].StartDate),CreateODBCDate(DateAdd('d', LoopIndex, attributes.KalendarRequest.getFirstDateOfWeek()))) GTE 0>
	<cfif CreateODBCDate(eventRecords[i].EndDate) gte CreateODBCDate(DateAdd('d', LoopIndex, attributes.KalendarRequest.getFirstDateOfWeek()))>
	<div class="eventdiv">
	<div class="timeHeader<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate> spandays</cfif>">
		<cfif eventRecords[i].isAllDayEvent> 
			all day event
		<cfelse>
			<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate>
				<cfif DateAdd('d',0,DateFormat(eventRecords[i].startDate)) eq thisDay>
					#DateFormat(eventRecords[i].StartDate, 'm/d')# #TimeFormat(eventRecords[i].StartDate, 'h:mm tt')#
				</cfif>
			<cfelse> 
				#TimeFormat(eventRecords[i].StartDate, 'h:mm tt')#
			</cfif>
			<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate>
				<cfif DateAdd('d',0,DateFormat(eventRecords[i].startDate)) neq thisDay>
					End #DateFormat(eventRecords[i].EndDate, "m/d")#
					<cfif TimeFormat(eventRecords[i].EndDate) NEQ  "12:00 AM"> 
						#TimeFormat(eventRecords[i].EndDate, 'h:mm tt')#
					</cfif>
				</cfif>
			</cfif>
		</cfif>
	</div>
	<!--- set the description --->
	<div class="eventDisplay"<cfif len(trim(eventRecords[i].Teaser)) OR len(trim(eventRecords[i].Description))> title="#Attributes.ToolTipFormatter.eventTitleTip(eventRecords[i].StartDate, eventRecords[i].EndDate, Trim(eventRecords[i].Title), KalendarConfig.getToolTipSubLength())#|#Attributes.ToolTipFormatter.eventBodyTip(eventRecords[i].Teaser, eventRecords[i].Description, KalendarConfig.getMaxDescriptionSize())#"</cfif><cfif KalendarConfig.getUseCategoryColors() AND Len(Trim(eventRecords[i].CategoryBGColor))> style="background-color: ###eventRecords[i].CategoryBGColor#;"</cfif>>
		<a title="#Trim(eventRecords[i].Title)#" href="#attributes.calendarLinkPage#?#eventRecords[i].EventIDLabel#=#eventRecords[i].EventID#&amp;View=#attributes.View#&amp;linkDate=#UrlEncodedFormat(attributes.KalendarRequest.getLinkDate())#<cfif len(attributes.urlAddString)>#attributes.urlAddString#</cfif>&KeepThis=true&TB_iframe=true&height=225&width=300" class="thickbox"<cfif KalendarConfig.getUseCategoryColors() AND Len(Trim(eventRecords[i].CategoryTextColor))> style="color: ###eventRecords[i].CategoryTextColor#;"</cfif>>#Trim(eventRecords[i].Title)#</a>
	</div>
	<!--- begin: microformat. Leave hidden --->
	<!--- TODO: verify these are accurate and foolproof --->
	<div style="display:none;" class="vevent">
	<span class="dtstamp">#DateFormat(Now(), "yyyy-mm-dd")#T#TimeFormat(Now(), "HH:mm:ss")#</span>
	<span class="summary title">#Trim(eventRecords[i].Title)#</span>
	<a href="#attributes.calendarLinkPage#?#eventRecords[i].EventIDLabel#=#eventRecords[i].EventID#&amp;View=#attributes.View#&amp;linkDate=#UrlEncodedFormat(attributes.KalendarRequest.getLinkDate())#<cfif len(attributes.urlAddString)>#attributes.urlAddString#</cfif>" class="url">Event Link</a>
	<div class="description">#eventRecords[i].Description#</div>
	<span class="dtstart" title="#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#T#TimeFormat(eventRecords[i].StartDate, "HH:mm:ss")#">#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#T#TimeFormat(eventRecords[i].StartDate, "HH:mm:ss")#</span>
	<cfif eventRecords[i].StartDate neq eventRecords[i].EndDate><span class="dtend" title="<cfif eventRecords[i].EndDate neq eventRecords[i].StartDate>#DateFormat(eventRecords[i].EndDate, "yyyy-mm-dd")#<cfelse>#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#</cfif>T#TimeFormat(eventRecords[i].EndDate, "HH:mm:ss")#"><cfif eventRecords[i].EndDate neq eventRecords[i].StartDate>#DateFormat(eventRecords[i].EndDate, "yyyy-mm-dd")#<cfelse>#DateFormat(eventRecords[i].StartDate, "yyyy-mm-dd")#</cfif>T#TimeFormat(eventRecords[i].EndDate, "HH:mm:ss")#</span></cfif>
	</div>
	<!--- end: microformat --->
	</cfif>
	</cfif>
	</div>
	</cfoutput>
	</cfloop>
	</td>
	</cfloop>
</tr>							
</table>